package com.tptech.nearme.service.implementation;

import java.util.List;

import javax.ejb.Stateless;
import javax.inject.Inject;

import com.tptech.nearme.data.LocationRepository;
import com.tptech.nearme.data.UserLocationRepository;
import com.tptech.nearme.data.UserRepository;
import com.tptech.nearme.model.User;
import com.tptech.nearme.model.UserLocation;
import com.tptech.nearme.service.IUserService;


@Stateless
public class UserService implements IUserService {

	@Inject
	private UserRepository repository;
	
	@Inject
	private UserLocationRepository userLocationRepository;
	
	@Inject
	private LocationRepository locationRepo;
	
	/* (non-Javadoc)
	 * @see com.tptech.nearme.service.implementation.IUserService#registerUser(com.tptech.nearme.model.User)
	 */
	@Override
	public void registerUser(User user){
		if(user.getUserid()!=null){
			throw new IllegalArgumentException("User must not have any id");
		}
		repository.save(user);
	}

	@Override
	public void registerLocation(Long userid, UserLocation location) {
		User user = repository.find(userid);
		location.setUser(user);
		location.setId(null);
		userLocationRepository.save(location);
		return;
	}

	@Override
	public List<UserLocation> getUserLocations(Long userid) {

		User user =  repository.loadUser(userid);
		return user.getPreferredLocations();
//		List<UserLocation> locationList =user.getPreferredLocations();
//		
//		return locationList;
	}


}
